package test5.lupeng.jf.com.teamdemo.adapter;


import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;

import java.util.ArrayList;

import test5.lupeng.jf.com.teamdemo.R;

//发布动态的适配器
public class SendDonTaiAdapter extends RecyclerView.Adapter {

    ArrayList<String> strings;

    public SendDonTaiAdapter(ArrayList<String> strings) {
        this.strings = strings;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_send_image, parent, false);
        SendDonTaiViewHolder holder = new SendDonTaiViewHolder(view);
        return holder;
    }

    public class SendDonTaiViewHolder extends RecyclerView.ViewHolder{

        private final ImageView iv_image;
        private final ImageView delete;

        public SendDonTaiViewHolder(View itemView) {
            super(itemView);
            iv_image = itemView.findViewById(R.id.iv_image);
            delete = itemView.findViewById(R.id.delete);
        }
    }


    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        final SendDonTaiViewHolder holder1 = (SendDonTaiViewHolder) holder;
        Glide.with(holder1.itemView.getContext())
                .load(strings.get(position))
                .centerCrop()
                .into(holder1.iv_image);

        //点击图片
        holder1.iv_image.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {

                holder1.delete.setVisibility(View.VISIBLE);

                holder1.delete.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        sendDonTaiInterface.clickListen(position);
                    }
                });
                return true;
            }
        });


    }

    @Override
    public int getItemCount() {
        return strings.size();
    }

    SendDonTaiInterface sendDonTaiInterface;

    public void setListen(SendDonTaiInterface sendDonTaiInterface){
        this.sendDonTaiInterface = sendDonTaiInterface;
    }

    public interface SendDonTaiInterface{

        void clickListen(int position);

    }


}
